const Actions = require('./actions');
const DB = require('app/db.js');
const monStorage = require('clientConfig/util/StoreData').monStorage;
const Storage = require('clientConfig/util/StoreData').Storage;
module.exports = Reflux.createStore({
    listenables: [Actions],
    data: {
        categories:[],//项目名称
        falut_total:[],//故障次数
        effective_rate:[],//有效率
        pesponse_rate:[],//响应率
    },

    onFetch: function(params, cb) {
        let t = this;
        let categories = [];
        let falut_total = [];
        let effective_rate = [];
        let pesponse_rate = [];

        DB.Proj.get_projs_fault({
            create_time: new Date(params.startTime).toLocaleDateString()+ " 00:00:00",
            finish_time: new Date(params.endTime).toLocaleDateString()+ " 23:00:00",
            id: Storage.get('user.id')
        }).then((content) => {// 成功
            content.map((item,index)=>{
                categories.push(item.proj_name);//项目名称
                falut_total.push(item.fault_total);//故障次数
                effective_rate.push(item.effective_rate*100);//有效率
                pesponse_rate.push(item.pesponse_rate*100);//响应率
            });
            t.data.categories = categories
            t.data.falut_total = falut_total
            t.data.effective_rate = effective_rate
            t.data.pesponse_rate = pesponse_rate
            t.updateComponent();
        }).catch((error) => { // 失败 or 有异常被捕获
           
        });
    },

    updateComponent: function() {
        this.trigger(this.data);
    },

    getInitialState: function() {
        return this.data;
    }
});
